from django import forms
from django.utils.datetime_safe import datetime

from api.conf.order_status import NOT_PAYED, NOT_SHIPPED, TO_BE_RECEIVED, FINISHED, USER_CANCEL, SYSTEM_CANCEL, \
    ORDER_ERROR
from app.models.area import Area
from app.models.fm_user import FMUser, USER_TYPE_SALES, USER_TYPE_USER

ORDER_STATUS_CHOICES = (
    (None, u'---------'),
    (NOT_PAYED, u'未付款'),
    (NOT_SHIPPED, u'待发货'),
    (TO_BE_RECEIVED, u'待收货'),
    (FINISHED, u'已完成'),
    (USER_CANCEL, u'用户取消订单'),
    (SYSTEM_CANCEL, u'系统取消订单'),
    (ORDER_ERROR, u'订单异常')
)


class OrderAnalysisForm(forms.Form):
    datetime_from = forms.DateTimeField(
        initial=datetime.today,
        label=u'开始时间',
    )
    datetime_to = forms.DateTimeField(
        initial=datetime.today,
        label=u'结束时间'
    )
    order_status = forms.ChoiceField(
        choices=ORDER_STATUS_CHOICES,
        required=False,
        label=u'订单状态',
        widget=forms.Select(attrs={'class': 'form-control'})
    )
    area = forms.ModelChoiceField(
        queryset=Area.objects.all(),
        required=False,
        label=u'片区',
        widget=forms.Select(attrs={'class': 'form-control'})
    )
    sales = forms.ModelChoiceField(
        queryset=FMUser.objects.filter(user_type=USER_TYPE_SALES),
        required=False,
        label=u'销售',
        widget=forms.Select(attrs={'class': 'form-control'})
    )
    user = forms.ModelChoiceField(
        queryset=FMUser.objects.filter(user_type=USER_TYPE_USER),
        required=False,
        label=u'用户',
        widget=forms.Select(attrs={'class': 'form-control'})
    )
